package com.zgm.ch04._2_1_4;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.Assert;

/**
 * 嵌入Bean的创建的两种方法：
 * 方法二：
 * 实现InitializingBean接口
 * @author Administrator
 *
 */
public abstract class SimpleBeanSupport implements InitializingBean {

	private String value;
	
	protected void initSimple() throws Exception{
		
	}
//	@Override
	public final void afterPropertiesSet() throws Exception {
		Assert.notNull(this.value, "value 的值必须设置！");
		System.out.println("自定义初始化开始");
		
		initSimple();
	}

	
	
	public static void main(String[] args){
//		BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("/META-INF/spring/ch03/_4_11/_4_11-context.xml"));
		//可以
		BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("com/zgm/ch04/_2_1_2/_2_1_2-context.xml"));
		//不行 
//		BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("classpath:com/zgm/ch03/_4_11/_4_11-context.xml"));
		
//		System.out.println(simpleBean);
	}
	
	/*@Override
	public String toString(){
		final StringBuilder sb = new StringBuilder();
		sb.append("SimpleBean");
		sb.append("{name=").append(name);
		sb.append(", age=").append(age);
		sb.append("}");
		
		return sb.toString();
		
	}*/



	public final void setValue(String value) {
		this.value = value;
	}


	public final String getValue() {
		return value;
	}
	
	
	
}
